package leetcode.D300.T264;

/**
 * @File Info: leetcode -- <Solution>
 * @Author: 18362
 * @Create: 2022-03-15 10:26:10 星期二
 */

class Solution {
    public int nthUglyNumber(int n) {
        int[] res = new int[n+1];
        res[1] = 1;
        for(int i2=1,i3=1,i5=1,i=2; i<=n; ++i) {
            int a2 = res[i2]*2, a3 = res[i3]*3, a5 = res[i5]*5;
            int min = Math.min(a2, Math.min(a3, a5));
            if (min == a2)  i2++;
            if (min == a3)  i3++;
            if (min == a5)  i5++;
            res[i] = min;
        }
        return res[n];
    }
}